/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.unice.miage.oobdoo.entity;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author Jeremy Romano
 */
@Entity
@XmlRootElement
public class Partage implements Serializable {
    private static final long serialVersionUID = 1L;

    @ManyToOne
    private Utilisateur utilisateur;

    @ManyToOne
    private Album album;

    private long creation;

    private boolean valide;

    private boolean vue;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private int id;

    public Partage(){}

    public Partage(final Utilisateur utilisateur, final Album album)
    {
        Date d = new Date();
        this.creation = d.getTime();
        this.utilisateur = utilisateur;
        this.album = album;
        // ---------------TODO----------------------------------------------------------------
        this.valide = true;
        this.vue = false;
    }

    public boolean isVue() {
        return vue;
    }

    public void setVue(boolean vue) {
        this.vue = vue;
    }

    public int getId() {
        return id;
    }

    public long getCreation() {
        return creation;
    }

    public void setCreation(long creation) {
        this.creation = creation;
    }

    public boolean isValide() {
        return valide;
    }

    public void setValide(boolean valide) {
        this.valide = valide;
    }

    public Album getAlbum() {
        return album;
    }

    public void setAlbum(Album album) {
        this.album = album;
    }

    public Utilisateur getUtilisateur() {
        return utilisateur;
    }

    public void setUtilisateur(Utilisateur utilisateur) {
        this.utilisateur = utilisateur;
    }

    public void setId(int id) {
        this.id = id;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (int) id;
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Partage)) {
            return false;
        }
        Partage other = (Partage) object;
        if (this.id != other.id) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Partage{" + "utilisateur=" + utilisateur.getLogin() + ", album=" + album.getNom() + ", creation=" + creation + ", valide=" + valide + ", id=" + id + '}';
    }


}
